#ifndef     __COMM_WRITE_HELPER_H
#define     __COMM_WRITE_HELPER_H

#include <stdint.h>
#include <utility>
#include "./frame.h"

template <typename CONN>
struct ConnWriteHelper {

    void ack(const conn::Frame &frame) {
        static_cast<CONN *>(this)->template write<conn::type::ACK>(
            frame.src(),
            frame.seq_cmd()
        );
    }

    void pong(const conn::Frame &frame) {
        static_cast<CONN *>(this)->template write<conn::type::PONG>(
            frame.src()
        );
    }

    template <typename... Ts>
    void result(const conn::Frame &frame, Ts&&... ts) {
        static_cast<CONN *>(this)->template write<conn::type::RESULT>(
			frame.src(),
            frame.seq_cmd(), 
			std::forward<Ts>(ts)...
		);
    }

    template <typename... Ts>
    void fast_res(const conn::Frame &frame, Ts&&... ts) {
        static_cast<CONN *>(this)->template write<conn::type::FAST_RES>(
            frame.src(),
            frame.seq_cmd(),
            frame.cmd(),
            std::forward<Ts>(ts)...
        );
    }

    template <typename... Ts>
    void notify(uint8_t dst, uint8_t cmd, Ts&&... ts) {
        static_cast<CONN *>(this)->template write<conn::type::NOTIFY>(
            dst,
            cmd,
            std::forward<Ts>(ts)...
        );
    }
};


#endif
